import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'

// 密钥对生成 http://web.chacuo.net/netrsakeypair
// /公钥 用于加密明文
const pubkey = `MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC/CcFvA+T8H/DIQAp5q7LApjDn
bvS9eYePbSSWPGWKW/Tt+9Q7TTj6WYNu5FWEy8UimulZh38apRGmZ8x6/li0k8yz
hdANebxic1L9DetMFM+5CZmK4GTbnArXqv6ei2xzouRE7VnV7kcRp/wM48/P9x5G
VQHMAScp1WpM4vTd6QIDAQAB`

//私钥 用于解密明文
const prikey = `MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAL8JwW8D5Pwf8MhA
CnmrssCmMOdu9L15h49tJJY8ZYpb9O371DtNOPpZg27kVYTLxSKa6VmHfxqlEaZn
zHr+WLSTzLOF0A15vGJzUv0N60wUz7kJmYrgZNucCteq/p6LbHOi5ETtWdXuRxGn
/Azjz8/3HkZVAcwBJynVakzi9N3pAgMBAAECgYA0VpTjOFrs5EdQZZM5IFw5wY5W
aaStoHUOS2Whr2xWSrlA1iSgFpkMpaeHoxD27+jTgUN7Hs8o2p6KS5fO/o4IedlH
XYAyg3Rn8uvsFSXiRw4Gi1D0BUh5UYL/U/J8Zc1wsGKbMPeXfPK0N8qe5Pr2LEtN
tScKyunt6PaWew6ugQJBAOM80rCxfDBSN6fi+Ig5PtCpBk7C6tizaNic77u4stDD
9sQGceo0sWg336RoEgVckf8mRLcMU8TgxuCI2WP+E1ECQQDXN/YQy3j0HG1yDo0D
BcvlD6Ye+oHis4HR5YR8oNab70yyG1peSNLYzyzYdu1JcXjOpIbHbJ+aH8sDEwxG
KIsZAkB++ugJUMTDA86SBGU5SjPtyeX6cTVmrqqyENBuKAHUYw0r8SYK6DMSt9ZD
OtyHHnl/CNVxLHRLGghIRHCmTb5hAkEAhkbC/n2ErIFkA4pyjlU6fmLCGYfgK8ol
kAisHXnYDBhEeMc6HaM/8cdoynGA4JascfkSoi/ycB2v8u4adVdsWQJBALwDaynf
DjRCcHnYpq123k2ys5YonniaexA5zoc3kpD1hp8TUMxyp139KIw1mjALj21MV8Hb
SSXjvbA+S+qynwE=`

// 加密
// txt 加密的密码
// type 是那种的加密 密钥
export function encrypt(txt) {
  if (!txt) return txt
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(pubkey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
// txt 加密的密码
// type 是那种的加密 密钥
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(prikey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}
